#include <gtk/gtk.h>
#include <stdio.h>

#include "gtkutils.h"

void sayHello() {
    printf("hello word\n");
}

enum {
    TEXT
};

createTreeModelFunc(build_combox_data) {
    GtkListStore *store = createListStore(1, G_TYPE_STRING);
    GtkTreeIter iter;

    GSList *list = NULL;
    list = g_slist_append(list, "Fuck");
    list = g_slist_append(list, "Fuck Linux");
    list = g_slist_append(list, "Fuck Windows");
    list = g_slist_append(list, "Fuck MacOs");

    for (GSList *siter = list; siter; siter = siter->next) {
        listStoreAppend(store, &iter);
        listStoreSet(store, &iter, TEXT, siter->data, -1);
    }
    return GTK_TREE_MODEL(store);
}

createCellLayoutDataFunc(combox_data) {}

static void activate(GtkApplication *app, gpointer user_data) {
    GtkWindow *window;

    window = createWindowWithTitleSize(app, "Hello World!", 500, 200);

    GtkLabel *helloworld = createLabel("Hello World!");

    GtkComboBox *combox = createComboBoxWithModel(build_combox_data());
    setCellLayout(combox, createCellRendererText(), "text", TEXT, combox_data, false);
    setComboBoxActive(combox, 0);
    GtkBox *mainbox = createBoxWithVerticalAppends(0, 
        helloworld, 
        combox,
        NULL
    );

    setBoxMargin(mainbox, 30, 30, 20, 20);
    // setBoxVerticalExpand(mainbox, true);
    setBoxVerticalAlign(mainbox, ACENTER);

    setWindowChild(window, 
        mainbox
    );

    showWindow(window);
}

int	main(int argc, char **argv) {

    GtkApplication *app;
    int status;

    app = createApplicationConnectActivate("gtk.example.template", 
                                G_APPLICATION_FLAGS_NONE, activate);
    // app = gtk_application_new("gtk.example.template", G_APPLICATION_FLAGS_NONE);
    // g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    // status = g_application_run(G_APPLICATION(app), argc, argv);
    // g_object_unref(app);
    status = runApplication(app, argc, argv);
    objectUnref(app);

    return status;
}

